<template>
  <div>
    <!-- 绘制顶部侧标尺-->
    <div>
      <div
        v-for="n in getVColumn"
        :key="n"
        :class="[(n - 1) % 10 === 0 ? 'cLongV' : 'cShortV', 'cItemV']"
        :style="getTopStyle(n)"
      >
        <div :style="getNumV(n)">
          {{ (n - 1) % 10 === 0 ? (n - 1) * 5 : "" }}
        </div>
      </div>
    </div>

    <!-- 绘制左侧标尺-->
    <div>
      <div
        v-for="n in getHColumn"
        :key="n"
        :style="{ top: (n - 1) * 5 + 40 + 'px', left: (n - 1) % 10 === 0 ? 31 + 'px' : 35 + 'px' }"
        :class="[(n - 1) % 10 === 0 ? 'cLongH' : 'cShortH', 'cItemH']"
      >
        <div class="cNumH">
          {{ (n - 1) % 10 === 0 ? (n - 1) * 5 : "" }}
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { computed, inject } from "vue";
import { designEditKey } from "@/hooks/lowcode/keys";
import type { TypeDesignProvide, TypeWidget } from "@/types/TypeDesign";

let { pageInfo } = inject(designEditKey) as TypeDesignProvide;

let getVColumn = computed(() => {
  return Math.floor(pageInfo.value.width / 5) + 1;
});

let getHColumn = computed(() => {
  return Math.floor(pageInfo.value.height / 5) + 1;
});

let getTopStyle = computed(() => {
  return (n: number) => {
    let left = (n - 1) * 5 + 40 + "px";
    let top = (n - 1) % 10 === 0 ? 28 + "px" : 33 + "px";
    return {
      left,
      top,
    };
  };
});

let getNumV = computed(() => {
  return (n: number) => {
    if (n - 1 == 0) {
      return {
        marginTop: "-16px",
        marginLeft: "-4px",
      };
    } else if (n - 1 == 10) {
      return {
        marginTop: "-16px",
        marginLeft: "-6px",
      };
    } else {
      return {
        marginTop: "-16px",
        marginLeft: "-10px",
      };
    }
  };
});
</script>

<style lang="scss" scoped>
.cItemV {
  position: absolute;
  font-size: 12px;
  color: #888888;
  background-color: yellow;
  height: 10px;
}

.cItemH {
  position: absolute;
  font-size: 12px;
  color: #888888;
  background-color: yellow;
  width: 10px;
}

// .cNumV {
//   margin-top: -16px;
//   margin-left: -10px;
// }

.cNumH {
  margin-left: -24px;
  margin-top: -8px;
}

.cLongV {
  width: 1px;
  height: 10px;
  background-color: red;
}

.cShortV {
  width: 1px;
  height: 5px;
  background-color: red;
}

.cLongH {
  width: 10px;
  height: 1px;
  background-color: red;
}

.cShortH {
  width: 5px;
  height: 1px;
  background-color: red;
}
</style>
